<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2016/11/9
 * Time: 14:20
 */

namespace App\Models;
use Log;
use TestingConfig;

class LogHelper {

    public static function getBaseLogPath()
    {
       return TestingConfig::getValue('log_file_base_path','/data/wwwlogs/testing');
    }

    /**
     * 记录操作日志
     *
     * @param mixed $data 需要记录的数据
     * @param string error_type 日志类型
     */
    public static function log($data, $log_type = 'warning', $log_format = "Y_m_d") {
        $path = self::getBaseLogPath().'/'.$log_type.'/';
        if(!is_dir($path)){
            make_dir($path);
        }

        $file = $path.date($log_format).'.log';
        if(is_array($data)){
            $msg = json_encode($data);
        }else{
            $msg = $data;
        }
        $datetime = date('Y-m-d H:i:s');
        $msg = $datetime.' '.$msg."\r\n";
        @file_put_contents($file, $msg, FILE_APPEND);
        return;
    }

    public static function info($message) {
        Log::info($message);
    }

    public static function warning($message) {
        Log::warning($message);
    }
}